;(function(global) {
  global.field = {
    template: `
                <div>
                  <div class="radio-container">
                    <!-- 综合题的样式  -->
                    <div v-if="examItemData.isComplex">
                      <div>
                        <div class="subject-type-name">{{ examItemData.partsTitle }}</div>
                      </div>
                      <div class="radio-dry" :class="{isShowDry:isShowDry}">{{ index+1 }}、<span v-html='examItemData.topic'></span>
                      </div>
                      <div class="radio-switch-container">
                        <div class="radio-switch" @click="showDry"></div>
                      </div>
                      <span v-if="examItemData.isComplex" class="redio-complex-dry-num">
                        第{{ examItemData.smallIndex+1 }}小题&nbsp;
                        {{ examItemData.describe }}
                      </span>
                      <div class="radio-complex-hr"></div>
                    </div>
  
                    <!-- 单选题的标题  -->
                    <div v-else  class="radio-type-two">
                      <div>
                      <div class="subject-type-name">{{ examItemData.partsTitle }}</div>
                      </div>
                      <span class="title-num">{{ index+1 }}、</span><span class="title-desc" v-html="examItemData.describe"></span>
                    </div>
  
                    <!-- 每道题答案选项 -->
                    <div>
                        <van-cell-group>
                            <van-field v-model="fieldValue" @blur="blur" :disabled="fieldDiabled" placeholder="请输入答案" type="textarea"/>
                        </van-cell-group>
                    </div>
  
                    <!-- 确认按钮 -->
                    <div v-show="isShowComfirm" class="checkbox-confirm" @click="confirmAnswer">确认</div>
                  </div>
  
                  <!-- 答案解析 -->
                  <div class="answer-analysis-container" v-show="isShowAnswerAnalysis">
                    <div class="answer-analysis-hr"></div>
                    <div class="answer-analysis-right-answer"><span class="answer-analysis-right-answer-span">正确答案：</span></div>
                    <div class="answer-analysis">
                      <p class="answer-analysis-p">解析</p>
                      <div class="answer-analysis-content" v-html="examItemData.resolu">
                      </div>
                    </div>
                  </div> 
                </div>
            `,
    props: ['where', 'examItemData', 'index'],
    data() {
      return {
        // 输入框的值
        fieldValue: '',
        // 用来存最后结果
        result: '',
        // 输入框是否可用
        fieldDiabled: false,
        // 判断是否是综合题
        isComplex: true,
        // 控制题干展开的开关
        switchControl: true,
        // 控制题干的展开
        isShowDry: true,
        // 控制解析答案的显示
        isShowAnswerAnalysis: false,
        // 用来决定 点击答案过后的样式
        answeredStyle: {},
        // 用来控制确定按钮的显示关闭
        isShowComfirm: true,
        // 用来判断是考试还是练习还是背题模式 0为考试模式 1为练习模式 2为背题模式
        // 每次进来之前需要判断模式 可以通过模式切换按钮切换
        doTestModule: 1
      }
    },
    computed: {},
    methods: {
      // 输入框失去焦点的时候
      blur() {
        if (this.where === 1) {
          const blurObj = {
            index: this.index,
            selectResult: this.fieldValue
          }
          if (this.fieldValue !== '') {
            blurObj.answerStatu = 'noJudge'
          } else {
            blurObj.answerStatu = 'undone'
          }
          this.$emit('answerToSheet', blurObj)
        }
      },
      // 模式转换事件
      reciteModel(type) {
        if (type === 1) {
          // 设为背题模式 显示出解析 并且输入框不可用
          this.isShowAnswerAnalysis = true
          this.fieldDiabled = true
          this.isShowComfirm = false
        }
        // 取消背题模式
        if (type === 2) {
          // 当本题没有选择答案的时候 去除背题模式的答案及解析
          if (this.result === '') {
            // 关闭背题模式 关闭解析 并且输入框可用
            this.isShowAnswerAnalysis = false
            this.fieldDiabled = false
            this.isShowComfirm = true
          }
        }
      },

      // 考试模式切换为练习模式的时候
      exerciseModel() {
        if (this.fieldValue !== '') {
          this.confirmAnswer()
        } else {
          this.isShowComfirm = true
        }
      },
      // 展开题干按钮事件
      showDry() {
        this.switchControl = !this.switchControl
        this.isShowDry = !this.isShowDry
      },
      // 确认按钮事件
      confirmAnswer() {
        this.result = this.fieldValue
        const confirmObj = {
          index: this.index,
          answerStatu: 'noJudge',
          selectResult: this.result
        }
        this.$emit('answerToSheet', confirmObj)
        if (this.where !== 1) {
          // 练习模式
          // 展示解析
          this.isShowAnswerAnalysis = true
          this.fieldDiabled = true
          this.isShowComfirm = false
        }
      }, // 将练习模式切换为背题模式的时候

      // 清除答题记录
      clearHistory() {
        this.fieldValue = ''
        this.result = ''
        this.fieldDiabled = false
        this.switchControl = true
        this.isShowDry = true
        this.isShowAnswerAnalysis = false
        this.answeredStyle = {}
        this.isShowComfirm = true
      }
    },
    created() {
      if (Number(this.where) === 1) {
        // 考试模式
        this.isShowComfirm = false
      }
    },
    mounted() {}
  }
})(window)
